package answer33;

/*多态*/
public class PolymorphicDemo {
    public static void main(String[] args) {
        //演示向上造型多态的的第二点应用；
        System.out.println("----------------------------------------------------");
        Animal[] animals=new Animal[5];
        animals[0]=new Dog("巴扎黑",6,"white");
        animals[1]=new Dog("白白",6,"white");
        animals[2]=new Dog("小黑",6,"white");
        animals[3]=new Chick("小黄",6,"white");
        animals[4]=new Fish("小红",6,"white");

        for(int i=0;i<animals.length;i++){
          System.out.println(animals[i].name);
          animals[i].eat();
          animals[i].drink();

          //向下造型多态的应用；强制类型转换。
          if(animals[i] instanceof Dog){
             Dog dog11=(Dog)animals[i];
             dog11.lookHouse();
          }
          if(animals[i] instanceof Chick){
             Chick chick11=(Chick)animals[i];
             chick11.layEggs();
          }
          if(animals[i] instanceof Swim){
             Swim swim11=(Swim)animals[i];
             swim11.swim();
          }
        }
        System.out.println("----------------------------------------------------");

        Master master=new Master();
        Animal dog2=new Dog("小白",6,"white");
        Animal chick3=new Chick("小黄",9,"yellow");
        Animal fish2=new Fish("大马哈",8,"red");


        //Animal animal=dog2;造型
        master.feed(dog2);
        master.feed(chick3);
        master.feed(fish2);
        System.out.println("----------------------------------------------------");
    }
}
